﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;

namespace DX_sharq.core
{
    public class Helper
    {
        public SelectList spisok(IEnumerable item, string stValue, string stText)
        {
            var list = new List<SelectListItem>();
            list.Clear();
            list.Add(new SelectListItem { Text = "- - - - - - - - - Танланг - - - - - - - - - - -", Value = "0" });
            list.AddRange(new SelectList(item, stValue, stText));
            return new SelectList(list, "Value", "Text");
        }

        public SelectList spisokSelect(IEnumerable item, string stValue, string stText, object selectValue)
        {
            var list = new List<SelectListItem>();
            list.Clear();
            list.Add(new SelectListItem { Text = "- - - - - - - - - Танланг - - - - - - - - - - -", Value = "0" });
            list.AddRange(new SelectList(item, stValue, stText, selectValue));
            return new SelectList(list, "Value", "Text", selectValue);
        }

        public string _file_kengaytma(string file)
        {
            int n = file.Length - 1;
            string s = "";
            char ch = file[n];
            while (n > 1 && ch != '.')
            {
                s = file[n] + s;
                n--;
                ch = file[n];
            }
            return '.' + s;
        }

        public string _get_file_name(int org_id, string _file_kengaytma)
        {
            return Convert.ToString(org_id) + "_" + Convert.ToString(DateTime.Now.Year) + "_" + Convert.ToString(DateTime.Now.Month) +
                   "_" + Convert.ToString(DateTime.Now.Day) + "_" + Convert.ToString(Guid.NewGuid()) + _file_kengaytma;
        }

        public Nullable<DateTime> get_Sana(string sana, string vaqt)
        {
            string exp = @"\A[0-3][0-9].[0-1][0-9].[0-9][0-9][0-9][0-9]$",
                exp2 = @"\A[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$";
            Nullable<DateTime> muhlat = null;
            if (Regex.Match(sana, exp).Success && Regex.Match(vaqt, exp2).Success)
            {
                muhlat = new DateTime(
                Convert.ToInt32(sana.Substring(6, 4)),
                Convert.ToInt32(sana.Substring(3, 2)),
                Convert.ToInt32(sana.Substring(0, 2)),
                Convert.ToInt32(vaqt.Substring(0, 2)),
                Convert.ToInt32(vaqt.Substring(3, 2)),
                Convert.ToInt32(vaqt.Substring(6, 2)));
            }
            return muhlat;
        }

        public bool SanaBuladimi(string _s)
        {
            string exp = @"\A[0-3][0-9].[0-1][0-9].[0-9][0-9][0-9][0-9]$";
            if (Regex.Match(_s, exp).Success)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public string getSanaTuliq(DateTime _dt)
        {
            int kun = _dt.Day;
            int oy = _dt.Month;
            int yil = _dt.Year;
            int hafta = (int)_dt.DayOfWeek;
            string[] oylar = { "январь", "февраль", "март", "апрел", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь" };
            string[] haftalar = { "Якшанба", "Душанба", "Сешанба", "Чоршанба", "Пайшанба", "Жума", "Шанба" };
            string _res = Convert.ToString(kun); _res += " " + oylar[oy - 1] + ", " + Convert.ToString(yil) + " йил. " + haftalar[hafta];
            return _res;
        }
    }
}